home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / HDGarbageCollector / INIT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-20  |  29.6 KB  |  1,472 lines  |  [TEXT/KAHL]

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <SetUpA4.h>
  4.  
  5. #undef _TEST
  6.  
  7.  
  8. #define ERRORDLOG            256
  9. #define INFODLOG            257
  10. #define MAPFILENAME            "HD Dirs List"
  11. #define FILELISTNAME        "HD File List"
  12. #define CREATOR                'Gbge'
  13. #define STUDENTDIRECTORY    "Student Work"
  14.  
  15. #define EQSTR            0
  16.  
  17.  
  18.  
  19. typedef  struct myVolumeInfoBlock
  20. {
  21. char        name[32];
  22. int            attrib;
  23. char        finderInfo[32];
  24. };
  25.  
  26. #define VolumeInfo    struct myVolumeInfoBlock
  27.  
  28.  
  29. typedef struct myDirInfoBlock
  30. {
  31. char        name[32];
  32. int            attrib;
  33. long        dirID;
  34. long        parentDirID;
  35. char        finderInfo[32];
  36. };
  37.  
  38. #define DirInfo    struct myDirInfoBlock
  39.  
  40.  
  41. typedef struct myFileInfoBlock
  42. {
  43. char    name[32];
  44. int        attrib;
  45. long    creator;
  46. long    type;
  47. long    creationDate;
  48. long    parentDirID;
  49. char    finderInfo[32];
  50. };
  51.  
  52. #define FileInfo    struct myFileInfoBlock
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. static CInfoPBRec    myCPB;
  60. static int            vRefNum;
  61. static char            errorString[256];
  62. static char            currentDirName[256];
  63. static DialogPtr    theDPtr = 0L;
  64. static long            numDirs = 0L,numFiles = 0L;
  65. static VolumeInfo    theVolInfo;
  66. static DirInfo        theDirInfo,*listOfDirs = 0L;
  67. static FileInfo        theFileInfo,*listOfFiles = 0L;
  68. static long            studentWorkDirID = 0L;
  69. static int            sysFolderVRefNum = 0;
  70.  
  71.  
  72. int main(void);
  73. static void    OpenInfoWindow(void);
  74. static void    SetInfoMessage(char *theMessage);
  75. static void    CloseInfoWindow(void);
  76. static int    InfoBreak(void);
  77. static int SetupVolRefNum(void);
  78. static void CenterWindow(WindowPtr wPtr);
  79. static pascal void HiliteDefaultButton(DialogPtr theDPtr,int whichItem);
  80. static void ErrorAlert(char *p0);
  81. static int LoadAndParseFiles(void);
  82. static void DisposeFileList(void);
  83. static int LoadAndParseDirs(void);
  84. static void DisposeDirList(void);
  85. static int OptionKey(void);
  86. static int CompareFiles(FileInfo *first,FileInfo *second);
  87. static long FindFile(FileInfo *theFileInfo);
  88. static int CompareDirs(DirInfo *first,DirInfo *second);
  89. static long FindDir(DirInfo *theDirInfo);
  90. static int ResetVolumeAndDirs(void);
  91. static int ResetFilesAndCollectGarbage(void);
  92. static int  ProcessDirectory(long theIODirID);
  93.  
  94.  
  95.  
  96. int main(void)
  97. {
  98.     RememberA0();
  99.     SetUpA4();
  100.     
  101.     InitGraf(&thePort);
  102.     InitFonts();
  103.     FlushEvents(everyEvent,0);
  104.     InitWindows();
  105.     TEInit();
  106.     InitDialogs(0L);
  107.     InitCursor();
  108.     MaxApplZone();
  109.     
  110.     DeskHook = 0L;
  111.     DragHook = 0L;
  112.     
  113.     ResetVolumeAndDirs();
  114.     ResetFilesAndCollectGarbage();
  115.     
  116.     DisposeFileList();
  117.     DisposeDirList();
  118.     
  119.     CloseInfoWindow();
  120.     
  121.     FlushEvents(everyEvent,0);
  122.     
  123.     RestoreA4();
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130. static void    OpenInfoWindow(void)
  131. {
  132. int                itemHit;
  133. EventRecord        theEvent;
  134. DialogPtr        tempDPtr;
  135. GrafPtr            oldPort;
  136.  
  137.     GetPort(&oldPort);
  138.  
  139.     theDPtr = GetNewDialog(INFODLOG, 0L,(WindowPtr) -1L);
  140.     
  141.     if (!theDPtr)
  142.     {
  143.         ErrorAlert("Can't get INFODLOG resource!");
  144.         ExitToShell();
  145.     }
  146.     
  147.     SetPort(theDPtr);
  148.     
  149.     CenterWindow(theDPtr);
  150.     ShowWindow(theDPtr);
  151.     
  152.     while (!GetNextEvent(updateMask,&theEvent) || theEvent.message != (long) theDPtr);
  153.     
  154.     DialogSelect(&theEvent,&tempDPtr,&itemHit);
  155.     
  156.     SetPort(oldPort);
  157. }
  158.  
  159.  
  160.  
  161.  
  162. static void    SetInfoMessage(char *theMessage)
  163. {
  164. int                itemHit,type,oldFont,oldSize;
  165. Handle            theItem;
  166. Rect            theRect;
  167. char            tempString[256];
  168. GrafPtr            oldPort;
  169. RgnHandle        theRgn;
  170.  
  171.     if (!theDPtr)
  172.         OpenInfoWindow();
  173.     
  174.     GetPort(&oldPort);
  175.     SetPort(theDPtr);
  176.     
  177.     oldFont = theDPtr->txFont;
  178.     oldSize = theDPtr->txSize;
  179.     
  180.     strcpy(tempString,theMessage);
  181.     CtoPstr(tempString);
  182.     GetDItem(theDPtr,2,&type,&theItem,&theRect);
  183.     
  184.     InsetRect(&theRect,-2,-2);
  185.     FrameRect(&theRect);
  186.     InsetRect(&theRect,2,2);
  187.     
  188.     theRgn = NewRgn();
  189.     ScrollRect(&theRect,0,-12,theRgn);
  190.     DisposeRgn(theRgn);
  191.     ClipRect(&theRect);
  192.     MoveTo(theRect.left + 3,theRect.bottom - 3);
  193.     
  194.     TextFont(geneva);
  195.     TextSize(10);
  196.     DrawString(tempString);
  197.     
  198.     
  199.     SetRect(&theRect,-32768,-32768,32767,32767);
  200.     ClipRect(&theRect);
  201.     
  202.     TextFont(oldFont);
  203.     TextSize(oldSize);
  204.     SetPort(oldPort);
  205.     
  206.     if (OptionKey())
  207.     {
  208.         while (!Button());
  209.         while (Button());
  210.     }
  211. }
  212.  
  213.  
  214.  
  215. static void    CloseInfoWindow(void)
  216. {
  217.     DisposDialog(theDPtr);
  218.     
  219.     theDPtr = 0L;
  220. }
  221.  
  222.  
  223.  
  224.  
  225. static int    InfoBreak(void)
  226. {
  227. int                itemHit, type;
  228. Handle            theItem;
  229. Rect            theRect;
  230. EventRecord        theEvent;
  231. DialogPtr        tempDPtr;
  232.  
  233.  
  234.     itemHit = 0;
  235.     
  236.     if (GetNextEvent(everyEvent,&theEvent))
  237.     {
  238.         if (!IsDialogEvent(&theEvent) || !DialogSelect(&theEvent,&tempDPtr,&itemHit) || tempDPtr!=theDPtr)
  239.             itemHit = 0;
  240.     }
  241.     
  242.     if (itemHit == 1)
  243.         return(TRUE);
  244.     else
  245.         return(FALSE);
  246. }
  247.  
  248.  
  249.  
  250.  
  251.  
  252. static int SetupVolRefNum(void)
  253. {
  254. long        freeBytes;
  255. int            errCode;
  256. char        volName[256];
  257. SysEnvRec    theWorld;
  258.  
  259.  
  260. #ifndef _TEST
  261.  
  262.     if ((errCode = GetVInfo(0,volName,&vRefNum,&freeBytes)) != noErr)
  263.     {
  264.         sprintf(errorString,"SetupVolRefNum:\rGetVInfo() error %d",errCode);
  265.         ErrorAlert(errorString);
  266.         return(errCode);
  267.     }
  268.     
  269.     if ((errCode = SysEnvirons(1,&theWorld)) != noErr)
  270.     {
  271.         sprintf(errorString,"SetupVolRefNum:\rSysEnvirons() error %d",errCode);
  272.         ErrorAlert(errorString);
  273.         return(errCode);
  274.     }
  275.     
  276.     sysFolderVRefNum = theWorld.sysVRefNum;
  277.  
  278. #else
  279.     
  280.     if ((errCode = GetVol(volName,&vRefNum)) != noErr)
  281.     {
  282.         sprintf(errorString,"SetupVolRefNum:\rGetVol() error %d",errCode);
  283.         ErrorAlert(errorString);
  284.         return(errCode);
  285.     }
  286.     
  287.     sysFolderVRefNum = vRefNum;
  288.  
  289. #endif
  290.  
  291.     
  292.     return(noErr);
  293. }
  294.  
  295.  
  296.  
  297.  
  298. static void CenterWindow(WindowPtr wPtr)
  299. {
  300. int        screenWidth,screenHeight,windowWidth,windowHeight,left,top;
  301.  
  302.     if (wPtr == 0L)
  303.         return;
  304.     
  305.     screenWidth = screenBits.bounds.right - screenBits.bounds.left;
  306.     screenHeight = screenBits.bounds.bottom - screenBits.bounds.top - 20;
  307.     
  308.     windowWidth = wPtr->portRect.right - wPtr->portRect.left;
  309.     windowHeight = wPtr->portRect.bottom - wPtr->portRect.top;
  310.     
  311.     
  312.     left = screenBits.bounds.left + (screenWidth - windowWidth)/2;
  313.     
  314.     top = screenBits.bounds.top + 20 + (screenHeight - windowHeight)/2;
  315.     
  316.     if (left < 0)
  317.         left = 0;
  318.     
  319.     if (top < 20)
  320.         top = 20;
  321.     
  322.     MoveWindow(wPtr,left,top,FALSE);
  323. }
  324.  
  325.  
  326.  
  327. static pascal void HiliteDefaultButton(DialogPtr theDPtr,int whichItem)
  328. {
  329. int            type;
  330. Handle        theItem;
  331. Rect        theRect;
  332.  
  333.     GetDItem(theDPtr, ((DialogPeek) theDPtr)->aDefItem, &type, &theItem, &theRect);
  334.     PenNormal();
  335.     PenSize(3,3);
  336.     InsetRect(&theRect,-4,-4);
  337.     FrameRoundRect(&theRect,16,16);
  338.     PenSize(1,1);
  339. }
  340.  
  341.  
  342.  
  343. static void ErrorAlert(char *p0)
  344. {
  345. GrafPtr            oldPort;
  346. DialogPtr        theDPtr,tempDPtr;
  347. int                itemHit, type;
  348. Handle            theItem;
  349. Rect            theRect;
  350. EventRecord        theEvent;
  351.  
  352.     GetPort(&oldPort);
  353.     
  354.     InitCursor();
  355.     
  356.     if (!(theDPtr = GetNewDialog(ERRORDLOG, NULL,(WindowPtr) -1L)))
  357.     {
  358.         SysBeep(1);
  359.         ExitToShell();
  360.     }
  361.     
  362.     SetPort(theDPtr);
  363.     
  364.     CenterWindow(theDPtr);
  365.     ShowWindow(theDPtr);
  366.     
  367.     ((DialogPeek) theDPtr)->aDefItem = 1;
  368.     
  369.     GetDItem(theDPtr, 3, &type, &theItem, &theRect);
  370.     SetDItem(theDPtr, 3, type, HiliteDefaultButton, &theRect);
  371.     
  372.     GetDItem(theDPtr, 2, &type, &theItem, &theRect);
  373.     CtoPstr(p0);
  374.     SetIText(theItem, p0);
  375.     PtoCstr(p0);
  376.     
  377.     if (GetNextEvent(updateMask,&theEvent) && theEvent.message == (long) theDPtr)
  378.         DialogSelect(&theEvent,&tempDPtr,&itemHit);
  379.     
  380.     SysBeep(1);
  381.     
  382.     do 
  383.     {
  384.         itemHit = 0;
  385.         
  386.         while (!GetNextEvent(everyEvent,&theEvent));
  387.         
  388.         if (theEvent.what==keyDown || theEvent.what==autoKey)
  389.         {
  390.             if ((theEvent.message & charCodeMask)=='\r' || (theEvent.message & charCodeMask)==0x03)
  391.                 itemHit = ((DialogPeek) theDPtr)->aDefItem;
  392.             else
  393.                 SysBeep(1);
  394.         }
  395.         
  396.         else
  397.         {
  398.             tempDPtr = (DialogPtr) 0L;
  399.             
  400.             if (!IsDialogEvent(&theEvent) || !DialogSelect(&theEvent,&tempDPtr,&itemHit) || tempDPtr!=theDPtr)
  401.                 itemHit = 0;
  402.         }
  403.         
  404.     } while (itemHit!=1);
  405.     
  406.     DisposDialog(theDPtr);
  407.     SetPort(oldPort);
  408. }
  409.  
  410.  
  411.  
  412.  
  413. static int LoadAndParseFiles(void)
  414. {
  415. char        filesFName[256];
  416. int            errCode;
  417. int            filesFRefNum;
  418. long        byteCount,theSize;
  419.  
  420.  
  421.     DisposeFileList();
  422.     
  423.     errCode = SetupVolRefNum();
  424.     
  425.     if (errCode != noErr)
  426.         return(errCode);
  427.     
  428.     strcpy(filesFName,FILELISTNAME);
  429.     CtoPstr(filesFName);
  430.     
  431.     errCode=FSOpen(filesFName,sysFolderVRefNum,&filesFRefNum);
  432.         
  433.     if (errCode!=noErr)
  434.     {
  435.         sprintf(errorString,"LoadAndParseFiles:\rFSOpen('%s') error %d",FILELISTNAME,errCode);
  436.         ErrorAlert(errorString);
  437.         return(errCode);
  438.     }
  439.     
  440.     if ((errCode = SetFPos(filesFRefNum,fsFromStart,0L))!=noErr)
  441.     {
  442.         FSClose(filesFRefNum);
  443.         sprintf(errorString,"LoadAndParseFiles:\rSetFPos('%s',fsFromStart) error %d",FILELISTNAME,errCode);
  444.         ErrorAlert(errorString);
  445.         return(errCode);
  446.     }
  447.     
  448.     if ((errCode = GetEOF(filesFRefNum,&theSize))!=noErr)
  449.     {
  450.         FSClose(filesFRefNum);
  451.         sprintf(errorString,"LoadAndParseFiles:\rGetEOF('%s') error %d",FILELISTNAME,errCode);
  452.         ErrorAlert(errorString);
  453.         return(errCode);
  454.     }
  455.     
  456.     numFiles = theSize / sizeof(FileInfo);
  457.     
  458.     if (theSize % sizeof(FileInfo))
  459.     {
  460.         DisposeFileList();
  461.         FSClose(filesFRefNum);
  462.         sprintf(errorString,"LoadAndParseFiles:\rbad file size-- %ld extra bytes ",theSize - (numFiles * sizeof(FileInfo)));
  463.         ErrorAlert(errorString);
  464.         return(errCode);
  465.     }
  466.     
  467.     
  468.     listOfFiles = (FileInfo *) NewPtr(numFiles * sizeof(FileInfo));
  469.     
  470.     byteCount = numFiles * sizeof(FileInfo);
  471.     
  472.     if ((errCode = FSRead(filesFRefNum,&byteCount,(Ptr) listOfFiles))!=noErr)
  473.     {
  474.         DisposeFileList();
  475.         FSClose(filesFRefNum);
  476.         sprintf(errorString,"LoadAndParseFiles:\rFSRead('%s') error %d",FILELISTNAME,errCode);
  477.         ErrorAlert(errorString);
  478.         return(errCode);
  479.     }
  480.     
  481.     if ((errCode = FSClose(filesFRefNum))!=noErr)
  482.     {
  483.         DisposeFileList();
  484.         sprintf(errorString,"LoadAndParseFiles:\rFSClose('%s') error %d",FILELISTNAME,errCode);
  485.         ErrorAlert(errorString);
  486.         return(errCode);
  487.     }
  488.     
  489.     
  490.     return(noErr);
  491. }
  492.  
  493.  
  494.  
  495.  
  496. static void DisposeFileList(void)
  497. {
  498.     if (listOfFiles)
  499.         DisposPtr(listOfFiles);
  500.     
  501.     listOfFiles = 0L;
  502.     numFiles = 0L;
  503. }
  504.  
  505.  
  506. static int LoadAndParseDirs(void)
  507. {
  508. char        dirsFName[256];
  509. int            errCode;
  510. int            dirsFRefNum;
  511. long        byteCount,theSize;
  512.  
  513.  
  514.     DisposeDirList();
  515.     
  516.     errCode = SetupVolRefNum();
  517.     
  518.     if (errCode != noErr)
  519.         return(errCode);
  520.     
  521.     strcpy(dirsFName,MAPFILENAME);
  522.     CtoPstr(dirsFName);
  523.     
  524.     errCode=FSOpen(dirsFName,sysFolderVRefNum,&dirsFRefNum);
  525.         
  526.     if (errCode!=noErr)
  527.     {
  528.         sprintf(errorString,"LoadAndParseDirs:\rFSOpen('%s') error %d",MAPFILENAME,errCode);
  529.         ErrorAlert(errorString);
  530.         return(errCode);
  531.     }
  532.     
  533.     if ((errCode = SetFPos(dirsFRefNum,fsFromStart,0L))!=noErr)
  534.     {
  535.         FSClose(dirsFRefNum);
  536.         sprintf(errorString,"LoadAndParseDirs:\rSetFPos('%s',fsFromStart) error %d",MAPFILENAME,errCode);
  537.         ErrorAlert(errorString);
  538.         return(errCode);
  539.     }
  540.     
  541.     if ((errCode = GetEOF(dirsFRefNum,&theSize))!=noErr)
  542.     {
  543.         FSClose(dirsFRefNum);
  544.         sprintf(errorString,"LoadAndParseDirs:\rGetEOF('%s') error %d",MAPFILENAME,errCode);
  545.         ErrorAlert(errorString);
  546.         return(errCode);
  547.     }
  548.     
  549.     
  550.     byteCount = sizeof(VolumeInfo);
  551.     
  552.     if ((errCode = FSRead(dirsFRefNum,&byteCount,&theVolInfo))!=noErr)
  553.     {
  554.         FSClose(dirsFRefNum);
  555.         sprintf(errorString,"LoadAndParseDirs:\rFSRead('%s') error %d",MAPFILENAME,errCode);
  556.         ErrorAlert(errorString);
  557.         return(errCode);
  558.     }
  559.     
  560.     theSize -= byteCount;
  561.     numDirs = theSize / sizeof(DirInfo);
  562.     
  563.     if (theSize % sizeof(DirInfo))
  564.     {
  565.         DisposeDirList();
  566.         FSClose(dirsFRefNum);
  567.         sprintf(errorString,"LoadAndParseDirs:\rbad file size-- %ld extra bytes ",theSize - (numDirs * sizeof(DirInfo)));
  568.         ErrorAlert(errorString);
  569.         return(errCode);
  570.     }
  571.     
  572.     listOfDirs = (DirInfo *) NewPtr(numDirs * sizeof(DirInfo));
  573.     
  574.     byteCount = numDirs * sizeof(DirInfo);
  575.     
  576.     if ((errCode = FSRead(dirsFRefNum,&byteCount,(Ptr) listOfDirs))!=noErr)
  577.     {
  578.         DisposeDirList();
  579.         FSClose(dirsFRefNum);
  580.         sprintf(errorString,"LoadAndParseDirs:\rFSRead('%s') error %d",MAPFILENAME,errCode);
  581.         ErrorAlert(errorString);
  582.         return(errCode);
  583.     }
  584.     
  585.     if ((errCode = FSClose(dirsFRefNum))!=noErr)
  586.     {
  587.         DisposeDirList();
  588.         sprintf(errorString,"LoadAndParseDirs:\rFSClose('%s') error %d",MAPFILENAME,errCode);
  589.         ErrorAlert(errorString);
  590.         return(errCode);
  591.     }
  592.     
  593.     
  594.     return(noErr);
  595. }
  596.  
  597.  
  598.  
  599.  
  600. static void DisposeDirList(void)
  601. {
  602.     if (listOfDirs)
  603.         DisposePtr(listOfDirs);
  604.     
  605.     listOfDirs = 0L;
  606.     numDirs = 0L;
  607. }
  608.  
  609.  
  610.  
  611.  
  612.  
  613. static int OptionKey(void)
  614. {
  615. char    theKeyMap[16];
  616.  
  617.     GetKeys(theKeyMap);
  618.     
  619.     if (theKeyMap[7] & 0x04)
  620.         return(TRUE);
  621.     else
  622.         return(FALSE);
  623. }
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631. static int CompareFiles(FileInfo *first,FileInfo *second)
  632. {
  633. int        errCode;
  634.  
  635.     if (first && second)
  636.     {
  637.         errCode = strcmp(first->name,second->name);
  638.         
  639.         if (errCode > 0)
  640.             return(1);
  641.         
  642.         else if (errCode < 0)
  643.             return(-1);
  644.         
  645.         
  646.         if (first->creator > second->creator)
  647.             return(1);
  648.         
  649.         else if (first->creator < second->creator)
  650.             return(-1);
  651.         
  652.         
  653.         
  654.         if (first->type > second->type)
  655.             return(1);
  656.         
  657.         else if (first->type < second->type)
  658.             return(-1);
  659.         
  660.         
  661.         
  662.         if (first->creationDate > second->creationDate)
  663.             return(1);
  664.         
  665.         else if (first->creationDate < second->creationDate)
  666.             return(-1);
  667.         
  668.         
  669.         
  670.         if (first->parentDirID > second->parentDirID)
  671.             return(1);
  672.         
  673.         else if (first->parentDirID < second->parentDirID)
  674.             return(-1);
  675.         
  676.         
  677.         
  678.         return(0);
  679.     }
  680.     
  681.     return(0);
  682. }
  683.  
  684.  
  685.  
  686. static long FindFile(FileInfo *theFileInfo)
  687. {
  688. register long    i,delta,found,matchWeight,tempWeight;
  689.  
  690.     i = 0;
  691.     
  692.     if (numFiles & 1L)
  693.         delta = (numFiles / 2L) + 1L;
  694.     else
  695.         delta = (numFiles / 2L);
  696.     
  697.     found = -1L;
  698.     
  699.     while (delta >= 1L && found < 0L)
  700.     {
  701.         tempWeight = CompareFiles(&(listOfFiles[i]),theFileInfo);
  702.         
  703.         if (tempWeight == 0L)
  704.             return(i);
  705.         
  706.         else if (tempWeight < 0L)
  707.             i += delta;
  708.         
  709.         else
  710.             i -= delta;
  711.         
  712.         
  713.         if (delta == 1L)
  714.             delta = 0L;
  715.         
  716.         else if (delta & 1L)
  717.             delta = (delta >> 1L) + 1L;
  718.         else
  719.             delta = (delta >> 1L);
  720.     }
  721.     
  722.     found = -1L;
  723.     matchWeight = 0;
  724.     
  725.     for (i = 0;i < numFiles;i++)
  726.     {
  727.         tempWeight = 0;
  728.         
  729.         if (strcmp(theFileInfo->name,listOfFiles[i].name) == EQSTR)
  730.             tempWeight++;
  731.         
  732.         if (theFileInfo->creator == listOfFiles[i].creator)
  733.             tempWeight++;
  734.         
  735.         if (theFileInfo->type == listOfFiles[i].type)
  736.             tempWeight++;
  737.         
  738.         if (theFileInfo->creationDate == listOfFiles[i].creationDate)
  739.             tempWeight++;
  740.         
  741.         if (theFileInfo->parentDirID == listOfFiles[i].parentDirID)
  742.             tempWeight++;
  743.         
  744.         if (theFileInfo->attrib == listOfFiles[i].attrib)
  745.             tempWeight++;
  746.         
  747.         if (strcmp(theFileInfo->finderInfo,listOfFiles[i].finderInfo) == EQSTR)
  748.             tempWeight++;
  749.         
  750.         
  751.         
  752.         if (tempWeight > matchWeight)
  753.         {
  754.             matchWeight = tempWeight;
  755.             found = i;
  756.         }
  757.     }
  758.     
  759.     
  760.     if (found >= 0L && (theFileInfo->creator != listOfFiles[found].creator || 
  761.         theFileInfo->type != listOfFiles[found].type || 
  762.         theFileInfo->creationDate != listOfFiles[found].creationDate))
  763.             found = -1L;
  764.     
  765.     return(found);
  766. }
  767.  
  768.  
  769.  
  770.  
  771.  
  772. static int CompareDirs(DirInfo *first,DirInfo *second)
  773. {
  774. int        errCode;
  775.  
  776.     if (first && second)
  777.     {
  778.         errCode = strcmp(first->name,second->name);
  779.         
  780.         if (errCode > 0)
  781.             return(1);
  782.         
  783.         else if (errCode < 0)
  784.             return(-1);
  785.         
  786.         
  787.         if (first->dirID > second->dirID)
  788.             return(1);
  789.         
  790.         else if (first->dirID < second->dirID)
  791.             return(-1);
  792.         
  793.         
  794.         
  795.         if (first->parentDirID > second->parentDirID)
  796.             return(1);
  797.         
  798.         else if (first->parentDirID < second->parentDirID)
  799.             return(-1);
  800.         
  801.         
  802.         if (first->attrib > second->attrib)
  803.             return(1);
  804.         
  805.         else if (first->attrib < second->attrib)
  806.             return(-1);
  807.         
  808.         
  809.         
  810.         errCode = strcmp(first->finderInfo,second->finderInfo);
  811.         
  812.         if (errCode > 0)
  813.             return(1);
  814.         
  815.         else if (errCode < 0)
  816.             return(-1);
  817.         
  818.         return(0);
  819.     }
  820.     
  821.     return(0);
  822. }
  823.  
  824.  
  825.  
  826. static long FindDir(DirInfo *theDirInfo)
  827. {
  828. register long    i,delta,result;
  829.  
  830.     i = 0;
  831.     
  832.     
  833.     if (numDirs & 1L)
  834.         delta = (numDirs / 2L) + 1L;
  835.     else
  836.         delta = (numDirs / 2L);
  837.     
  838.     
  839.     while (delta >= 1L)
  840.     {
  841.         result = CompareDirs(&(listOfDirs[i]),theDirInfo);
  842.         
  843.         if (result == 0L)
  844.             return(i);
  845.         
  846.         else if (result < 0L)
  847.             i += delta;
  848.         
  849.         else
  850.             i -= delta;
  851.         
  852.         
  853.         if (delta == 1L)
  854.             delta = 0L;
  855.         
  856.         else if (delta & 1L)
  857.             delta = (delta >> 1L) + 1L;
  858.         else
  859.             delta = (delta >> 1L);
  860.     }
  861.     
  862.     
  863.     for (i = 0;i < numDirs;i++)
  864.     {
  865.         if (theDirInfo->dirID == listOfDirs[i].dirID)
  866.             return(i);
  867.     }
  868.     
  869.     return(-1L);
  870. }
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880. static int ResetVolumeAndDirs(void)
  881. {
  882. int                errCode;
  883. HParamBlockRec    myHPB;
  884. CMovePBRec        myCMovePB;
  885. WDPBRec            myWDPB;
  886. int                j,i;
  887. char            tempString[256];
  888. long            theParentDirID;
  889.  
  890.     errCode = SetupVolRefNum();
  891.     
  892.     if (errCode != noErr)
  893.         return(errCode);
  894.     
  895.     tempString[0] = 0;
  896.     
  897.     myHPB.volumeParam.ioCompletion = 0L;
  898.     myHPB.volumeParam.ioNamePtr = (StringPtr) &tempString;
  899.     myHPB.volumeParam.ioVRefNum = vRefNum;
  900.     myHPB.volumeParam.ioVolIndex = 0;
  901.     
  902.     errCode = PBHGetVInfo(&myHPB,FALSE);
  903.     
  904.     if (errCode != noErr)
  905.     {
  906.         sprintf(errorString,"ResetVolumeAndDirs:\rPBHGetVInfo() error %d",errCode);
  907.         ErrorAlert(errorString);
  908.         return(errCode);
  909.     }
  910.     
  911.     SetInfoMessage("Loading previously saved volume/directory information");
  912.     
  913.     errCode = LoadAndParseDirs();
  914.     
  915.     if (errCode != noErr)
  916.         return(errCode);
  917.     
  918.     PtoCstr(tempString);
  919.     errCode = strcmp(tempString,theVolInfo.name);
  920.     CtoPstr(tempString);
  921.     
  922.     if (errCode != EQSTR)
  923.     {
  924.         PtoCstr(tempString);
  925.         sprintf(errorString,"Renaming volume from '%s' to '%s'",tempString,theVolInfo.name);
  926.         CtoPstr(tempString);
  927.         SetInfoMessage(errorString);
  928.         
  929.         strcpy(errorString,theVolInfo.name);
  930.         CtoPstr(errorString);
  931.         
  932.         myHPB.volumeParam.ioCompletion = 0L;
  933.         myHPB.volumeParam.ioNamePtr = 0L;
  934.         myHPB.volumeParam.ioVRefNum = vRefNum;
  935.         myHPB.ioParam.ioMisc = (Ptr) &errorString;
  936.         myHPB.fileParam.ioDirID = 0;
  937.         
  938.         errCode = PBHRename(&myHPB,FALSE);
  939.         
  940.         if (errCode != noErr)
  941.         {
  942.             PtoCstr(tempString);
  943.             sprintf(errorString,"ResetVolumeAndDirs:\rPBHRename('%s' -> '%s') error %d",tempString,theVolInfo.name,errCode);
  944.             CtoPstr(tempString);
  945.             ErrorAlert(errorString);
  946.         }
  947.         
  948.         else
  949.         {
  950.             strcpy(tempString,theVolInfo.name);
  951.             CtoPstr(tempString);
  952.         }
  953.     }
  954.     
  955.     
  956.     myHPB.volumeParam.ioCompletion = 0L;
  957.     myHPB.volumeParam.ioNamePtr = (StringPtr) &tempString;
  958.     myHPB.volumeParam.ioVAtrb = theVolInfo.attrib;
  959.     
  960.     for (j=0;j<32;j++)
  961.         ((unsigned char *) &(myHPB.volumeParam.ioVFndrInfo))[j] = theVolInfo.finderInfo[j];
  962.     
  963.     SetInfoMessage("Resetting volume info");
  964.     
  965.     errCode = PBSetVInfo(&myHPB,FALSE);
  966.     
  967.     if (errCode != noErr)
  968.     {
  969.         sprintf(errorString,"ResetVolumeAndDirs:\rPBSetVInfo() error %d",errCode);
  970.         ErrorAlert(errorString);
  971.         return(errCode);
  972.     }
  973.     
  974.     SetInfoMessage("Beginning reset of directory information");
  975.     
  976.     for (i=0;i<numDirs;i++)
  977.     {
  978.         if (InfoBreak())
  979.         {
  980.             DisposeDirList();
  981.             return(-1);
  982.         }
  983.         
  984.         tempString[0] = 0;
  985.         
  986.         myCPB.dirInfo.ioCompletion = 0L;
  987.         myCPB.dirInfo.ioNamePtr = (StringPtr) &tempString;
  988.         myCPB.dirInfo.ioVRefNum = vRefNum;
  989.         myCPB.dirInfo.ioFDirIndex = -1;
  990.         myCPB.dirInfo.ioDrDirID = listOfDirs[i].dirID;
  991.         
  992.         errCode = PBGetCatInfo(&myCPB,FALSE);
  993.         
  994.         if (errCode == fnfErr)
  995.         {
  996.             sprintf(errorString,"ResetVolumeAndDirs:\rPBGetCatInfo('%s') error %d \r\rDirectory has probably been deleted...",listOfDirs[i].name,errCode);
  997.             ErrorAlert(errorString);
  998.         }
  999.         
  1000.         else if (errCode != noErr)
  1001.         {
  1002.             sprintf(errorString,"ResetVolumeAndDirs:\rPBGetCatInfo('%s') error %d",listOfDirs[i].name,errCode);
  1003.             ErrorAlert(errorString);
  1004.         }
  1005.         
  1006.         else
  1007.         {
  1008.             theParentDirID = myCPB.dirInfo.ioDrParID;
  1009.             
  1010.             PtoCstr(tempString);
  1011.             errCode = strcmp(tempString,listOfDirs[i].name);
  1012.             CtoPstr(tempString);
  1013.             
  1014.             if (errCode != EQSTR)
  1015.             {
  1016.                 myWDPB.ioCompletion = 0L;
  1017.                 myWDPB.ioNamePtr = 0L;
  1018.                 myWDPB.ioVRefNum = vRefNum;
  1019.                 myWDPB.ioWDProcID = CREATOR;
  1020.                 myWDPB.ioWDDirID = myCPB.dirInfo.ioDrParID;
  1021.                 
  1022.                 errCode = PBOpenWD(&myWDPB,FALSE);
  1023.                 
  1024.                 if (errCode != noErr)
  1025.                 {
  1026.                     sprintf(errorString,"ResetVolumeAndDirs:\rPBOpenWD() error %d",errCode);
  1027.                     ErrorAlert(errorString);
  1028.                 }
  1029.                 
  1030.                 else
  1031.                 {
  1032.                     PtoCstr(tempString);
  1033.                     sprintf(errorString,"Renaming directory from '%s' to '%s'",tempString,listOfDirs[i].name);
  1034.                     CtoPstr(tempString);
  1035.                     SetInfoMessage(errorString);
  1036.                     
  1037.                     strcpy(errorString,listOfDirs[i].name);
  1038.                     CtoPstr(errorString);
  1039.                     
  1040.                     myHPB.fileParam.ioCompletion = 0L;
  1041.                     myHPB.fileParam.ioNamePtr = (StringPtr) tempString;
  1042.                     myHPB.fileParam.ioVRefNum = myWDPB.ioVRefNum;
  1043.                     myHPB.ioParam.ioMisc = (Ptr) &errorString;
  1044.                     myHPB.fileParam.ioDirID = 0L;
  1045.                     
  1046.                     errCode = PBHRename(&myHPB,FALSE);
  1047.                     
  1048.                     if (errCode != noErr)
  1049.                     {
  1050.                         PtoCstr(tempString);
  1051.                         sprintf(errorString,"ResetVolumeAndDirs:\rPBHRename('%s' -> '%s') error %d",tempString,listOfDirs[i].name,errCode);
  1052.                         CtoPstr(tempString);
  1053.                         ErrorAlert(errorString);
  1054.                     }
  1055.                     
  1056.                     else
  1057.                     {
  1058.                         strcpy(tempString,listOfDirs[i].name);
  1059.                         CtoPstr(tempString);
  1060.                     }
  1061.                     
  1062.                     errCode = PBCloseWD(&myWDPB,FALSE);
  1063.                 }
  1064.             }
  1065.             
  1066.             myCPB.dirInfo.ioCompletion = 0L;
  1067.             myCPB.dirInfo.ioNamePtr = 0L;
  1068.             myCPB.dirInfo.ioVRefNum = vRefNum;
  1069.             myCPB.dirInfo.ioFlAttrib = listOfDirs[i].attrib;
  1070.             myCPB.dirInfo.ioDrDirID = listOfDirs[i].dirID;
  1071.             
  1072.             for (j=0;j<16;j++)
  1073.                 ((char *) &(myCPB.dirInfo.ioDrUsrWds))[j] = listOfDirs[i].finderInfo[j];
  1074.             
  1075.             for (j=0;j<16;j++)
  1076.                 ((char *) &(myCPB.dirInfo.ioDrFndrInfo))[j] = listOfDirs[i].finderInfo[j + 16];
  1077.             
  1078.             errCode = PBSetCatInfo(&myCPB,FALSE);
  1079.             
  1080.             if (errCode != noErr)
  1081.             {
  1082.                 PtoCstr(tempString);
  1083.                 sprintf(errorString,"ResetVolumeAndDirs:\rPBSetCatInfo(%s) error %d",tempString,errCode);
  1084.                 CtoPstr(tempString);
  1085.                 ErrorAlert(errorString);
  1086.             }
  1087.             
  1088.             if (theParentDirID != listOfDirs[i].parentDirID)
  1089.             {
  1090.                 PtoCstr(tempString);
  1091.                 sprintf(errorString,"Moving '%s'",tempString);
  1092.                 CtoPstr(tempString);
  1093.                 SetInfoMessage(errorString);
  1094.                 
  1095.                 myCMovePB.ioCompletion = 0L;
  1096.                 myCMovePB.ioNamePtr = 0L;
  1097.                 myCMovePB.ioVRefNum = vRefNum;
  1098.                 myCMovePB.ioNewName = 0L;
  1099.                 myCMovePB.ioNewDirID = listOfDirs[i].parentDirID;
  1100.                 myCMovePB.ioDirID = listOfDirs[i].dirID;
  1101.                 
  1102.                 errCode = PBCatMove(&myCMovePB,FALSE);
  1103.                 
  1104.                 if (errCode != noErr)
  1105.                 {
  1106.                     PtoCstr(tempString);
  1107.                     sprintf(errorString,"ResetVolumeAndDirs:\rPBCatMove(%s) error %d",tempString,errCode);
  1108.                     CtoPstr(tempString);
  1109.                     ErrorAlert(errorString);
  1110.                 }
  1111.             }
  1112.         }
  1113.     }
  1114.     
  1115.     DisposeDirList();
  1116. }
  1117.  
  1118.  
  1119.  
  1120.  
  1121. static int ResetFilesAndCollectGarbage(void)
  1122. {
  1123. int        errCode;
  1124. char    tempString[256];
  1125.  
  1126.  
  1127.     errCode = SetupVolRefNum();
  1128.     
  1129.     if (errCode != noErr)
  1130.         return(errCode);
  1131.     
  1132.     errCode = LoadAndParseDirs();
  1133.     
  1134.     if (errCode != noErr)
  1135.         return(errCode);
  1136.     
  1137.     errCode = LoadAndParseFiles();
  1138.     
  1139.     if (errCode != noErr)
  1140.         return(errCode);
  1141.     
  1142.     strcpy(tempString,":");
  1143.     strcat(tempString,STUDENTDIRECTORY);
  1144.     strcat(tempString,":");
  1145.     CtoPstr(tempString);
  1146.     
  1147.     myCPB.dirInfo.ioCompletion = 0L;
  1148.     myCPB.dirInfo.ioNamePtr = (StringPtr) &tempString;
  1149.     myCPB.dirInfo.ioVRefNum = vRefNum;
  1150.     myCPB.dirInfo.ioFDirIndex = 0;
  1151.     myCPB.dirInfo.ioDrDirID = 0L;
  1152.     
  1153.     errCode = PBGetCatInfo(&myCPB,FALSE);
  1154.     
  1155.     if (errCode!=noErr && errCode!=fnfErr)
  1156.     {
  1157.         sprintf(errorString,"ResetFilesAndCollectGarbage:\rPBGetCatInfo error %d",errCode);
  1158.         ErrorAlert(errorString);
  1159.         return(errCode);
  1160.     }
  1161.     
  1162.     studentWorkDirID = myCPB.dirInfo.ioDrDirID;
  1163.     
  1164.     strcpy(currentDirName,theVolInfo.name);
  1165.     
  1166.     ProcessDirectory(0L);
  1167.     
  1168.     FlushVol("\p",vRefNum);
  1169.     
  1170. }
  1171.  
  1172.  
  1173.  
  1174.  
  1175. static int  ProcessDirectory(long theIODirID)
  1176. {
  1177. int                index,errCode,j;
  1178. char            tempString[256];
  1179. long            match;
  1180. CMovePBRec        myCMovePB;
  1181. WDPBRec            myWDPB;
  1182. HParamBlockRec    myHPB;
  1183.  
  1184.  
  1185.     if (InfoBreak())
  1186.         return(-1);
  1187.     
  1188.     if (currentDirName[0])
  1189.     {
  1190.         sprintf(errorString,"Checking %s",currentDirName);
  1191.         SetInfoMessage(errorString);
  1192.     }
  1193.     
  1194.     index = 1;
  1195.         
  1196.     do
  1197.     {
  1198.         tempString[0] = 0;
  1199.         
  1200.         myCPB.hFileInfo.ioCompletion = 0L;
  1201.         myCPB.hFileInfo.ioNamePtr = (StringPtr) &tempString;
  1202.         myCPB.hFileInfo.ioVRefNum = vRefNum;
  1203.         myCPB.hFileInfo.ioFDirIndex = index++;
  1204.         myCPB.hFileInfo.ioDirID = theIODirID;
  1205.         
  1206.         errCode = PBGetCatInfo(&myCPB,FALSE);
  1207.         
  1208.         if (errCode!=noErr && errCode!=fnfErr)
  1209.         {
  1210.             sprintf(errorString,"ProcessDirectory:\rPBGetCatInfo error %d",errCode);
  1211.             ErrorAlert(errorString);
  1212.             return(errCode);
  1213.         }
  1214.         
  1215.         else if (errCode == noErr)
  1216.         {
  1217.             PtoCstr(tempString);
  1218.             
  1219.             if (myCPB.hFileInfo.ioFlAttrib & 0x10)
  1220.             {
  1221.                 strcpy(theDirInfo.name,tempString);
  1222.                 theDirInfo.dirID = myCPB.dirInfo.ioDrDirID;
  1223.                 theDirInfo.parentDirID = myCPB.dirInfo.ioDrParID;
  1224.                 theDirInfo.attrib = myCPB.dirInfo.ioFlAttrib;
  1225.                 
  1226.                 for (j=0;j<16;j++)
  1227.                     theDirInfo.finderInfo[j] = ((char *) &(myCPB.dirInfo.ioDrUsrWds))[j];
  1228.                 
  1229.                 for (j=0;j<16;j++)
  1230.                     theDirInfo.finderInfo[j + 16] = ((char *) &(myCPB.dirInfo.ioDrFndrInfo))[j];
  1231.                 
  1232.                 match = FindDir(&theDirInfo);
  1233.                 
  1234.                 if (myCPB.dirInfo.ioDrParID != studentWorkDirID && (match < 0L || CompareDirs(&(listOfDirs[match]),&theDirInfo) != 0))
  1235.                 {
  1236.                     sprintf(errorString,"Moving directory '%s' to %s directory",tempString,STUDENTDIRECTORY);
  1237.                     SetInfoMessage(errorString);
  1238.                     
  1239.                     CtoPstr(tempString);
  1240.                     
  1241.                     myCMovePB.ioCompletion = 0L;
  1242.                     myCMovePB.ioNamePtr = 0L;
  1243.                     myCMovePB.ioVRefNum = vRefNum;
  1244.                     myCMovePB.ioNewName = 0L;
  1245.                     myCMovePB.ioNewDirID = studentWorkDirID;
  1246.                     myCMovePB.ioDirID = myCPB.dirInfo.ioDrDirID;
  1247.                     
  1248.                     errCode = PBCatMove(&myCMovePB,FALSE);
  1249.                     
  1250.                     if (errCode != noErr)
  1251.                     {
  1252.                         PtoCstr(tempString);
  1253.                         sprintf(errorString,"ProcessDirectory:\rPBCatMove(%s) error %d",tempString,errCode);
  1254.                         CtoPstr(tempString);
  1255.                         ErrorAlert(errorString);
  1256.                         errCode = noErr;
  1257.                     }
  1258.                     
  1259.                     else
  1260.                         index--;
  1261.                 }
  1262.             }
  1263.             
  1264.             else
  1265.             {
  1266.                 theFileInfo.type = myCPB.hFileInfo.ioFlFndrInfo.fdType;
  1267.                 theFileInfo.creator = myCPB.hFileInfo.ioFlFndrInfo.fdCreator;
  1268.                 theFileInfo.creationDate = myCPB.hFileInfo.ioFlCrDat;
  1269.                 theFileInfo.parentDirID = myCPB.hFileInfo.ioFlParID;
  1270.                 theFileInfo.attrib = myCPB.hFileInfo.ioFlAttrib;
  1271.                 strcpy(theFileInfo.name,tempString);
  1272.                 
  1273.                 for (j=0;j<16;j++)
  1274.                     theFileInfo.finderInfo[j] = ((char *) &(myCPB.hFileInfo.ioFlFndrInfo))[j];
  1275.                 
  1276.                 for (j=0;j<16;j++)
  1277.                     theFileInfo.finderInfo[j + 16] = ((char *) &(myCPB.hFileInfo.ioFlXFndrInfo))[j];
  1278.                 
  1279.                 match = FindFile(&theFileInfo);
  1280.                 
  1281.                 if (match < 0L && myCPB.hFileInfo.ioFlParID != studentWorkDirID)
  1282.                 {
  1283.                     sprintf(errorString,"Moving file '%s' to %s directory",tempString,STUDENTDIRECTORY);
  1284.                     SetInfoMessage(errorString);
  1285.                     
  1286.                     CtoPstr(tempString);
  1287.                     
  1288.                     myCMovePB.ioCompletion = 0L;
  1289.                     myCMovePB.ioNamePtr = (StringPtr) &tempString;
  1290.                     myCMovePB.ioVRefNum = vRefNum;
  1291.                     myCMovePB.ioNewName = 0L;
  1292.                     myCMovePB.ioNewDirID = studentWorkDirID;
  1293.                     myCMovePB.ioDirID = myCPB.hFileInfo.ioFlParID;
  1294.                     
  1295.                     errCode = PBCatMove(&myCMovePB,FALSE);
  1296.                     
  1297.                     if (errCode != noErr)
  1298.                     {
  1299.                         PtoCstr(tempString);
  1300.                         sprintf(errorString,"ProcessDirectory:\rPBCatMove(%s) error %d",tempString,errCode);
  1301.                         CtoPstr(tempString);
  1302.                         ErrorAlert(errorString);
  1303.                         errCode = noErr;
  1304.                     }
  1305.                     
  1306.                     else
  1307.                         index--;
  1308.                 }
  1309.                 
  1310.                 else
  1311.                 {
  1312.                     CtoPstr(tempString);
  1313.                     
  1314.                     myCPB.hFileInfo.ioCompletion = 0L;
  1315.                     myCPB.hFileInfo.ioNamePtr = (StringPtr) &tempString;
  1316.                     myCPB.hFileInfo.ioVRefNum = vRefNum;
  1317.                     myCPB.hFileInfo.ioFlAttrib = listOfFiles[match].attrib;
  1318.                     myCPB.hFileInfo.ioDirID = myCPB.hFileInfo.ioFlParID;
  1319.                     
  1320.                     for (j=0;j<16;j++)
  1321.                         ((char *) &(myCPB.hFileInfo.ioFlFndrInfo))[j] = listOfFiles[match].finderInfo[j];
  1322.                     
  1323.                     for (j=0;j<16;j++)
  1324.                         ((char *) &(myCPB.hFileInfo.ioFlXFndrInfo))[j] = listOfFiles[match].finderInfo[j + 16];
  1325.                     
  1326.                     errCode = PBSetCatInfo(&myCPB,FALSE);
  1327.                     
  1328.                     PtoCstr(tempString);
  1329.                     
  1330.                     if (errCode != noErr)
  1331.                     {
  1332.                         sprintf(errorString,"ProcessDirectory:\rPBSetCatInfo(%s) error %d",tempString,errCode);
  1333.                         ErrorAlert(errorString);
  1334.                         errCode = noErr;
  1335.                     }
  1336.                     
  1337.                     
  1338.                     if (strcmp(listOfFiles[match].name,theFileInfo.name) != EQSTR)
  1339.                     {
  1340.                         myWDPB.ioCompletion = 0L;
  1341.                         myWDPB.ioNamePtr = 0L;
  1342.                         myWDPB.ioVRefNum = vRefNum;
  1343.                         myWDPB.ioWDProcID = CREATOR;
  1344.                         myWDPB.ioWDDirID = myCPB.hFileInfo.ioFlParID;
  1345.                         
  1346.                         errCode = PBOpenWD(&myWDPB,FALSE);
  1347.                         
  1348.                         if (errCode != noErr)
  1349.                         {
  1350.                             sprintf(errorString,"ProcessDirectory:\rPBOpenWD() error %d",errCode);
  1351.                             ErrorAlert(errorString);
  1352.                             errCode = noErr;
  1353.                         }
  1354.                         
  1355.                         else
  1356.                         {
  1357.                             sprintf(errorString,"Renaming file from '%s' to '%s'",tempString,listOfFiles[match].name);
  1358.                             SetInfoMessage(errorString);
  1359.                             
  1360.                             strcpy(errorString,listOfFiles[match].name);
  1361.                             CtoPstr(errorString);
  1362.                             CtoPstr(tempString);
  1363.                             
  1364.                             myHPB.fileParam.ioCompletion = 0L;
  1365.                             myHPB.fileParam.ioNamePtr = (StringPtr) tempString;
  1366.                             myHPB.fileParam.ioVRefNum = myWDPB.ioVRefNum;
  1367.                             myHPB.ioParam.ioMisc = (Ptr) &errorString;
  1368.                             myHPB.fileParam.ioDirID = 0L;
  1369.                             
  1370.                             errCode = PBHRename(&myHPB,FALSE);
  1371.                             
  1372.                             PtoCstr(tempString);
  1373.                                 
  1374.                             if (errCode != noErr)
  1375.                             {
  1376.                                 sprintf(errorString,"ProcessDirectory:\rPBHRename('%s' -> '%s') error %d",tempString,listOfFiles[match].name,errCode);
  1377.                                 ErrorAlert(errorString);
  1378.                                 errCode = noErr;
  1379.                             }
  1380.                             
  1381.                             else
  1382.                                 strcpy(tempString,listOfFiles[match].name);
  1383.                             
  1384.                             PBCloseWD(&myWDPB,FALSE);
  1385.                         }
  1386.                     }
  1387.                 
  1388.                     if (listOfFiles[match].parentDirID != myCPB.hFileInfo.ioFlParID)
  1389.                     {
  1390.                          sprintf(errorString,"Moving file '%s'",tempString);
  1391.                         CtoPstr(tempString);
  1392.                         SetInfoMessage(errorString);
  1393.                         
  1394.                         myCMovePB.ioCompletion = 0L;
  1395.                         myCMovePB.ioNamePtr = (StringPtr) &tempString;
  1396.                         myCMovePB.ioVRefNum = vRefNum;
  1397.                         myCMovePB.ioNewName = 0L;
  1398.                         myCMovePB.ioNewDirID = listOfFiles[match].parentDirID;
  1399.                         myCMovePB.ioDirID = myCPB.hFileInfo.ioFlParID;
  1400.                         
  1401.                         errCode = PBCatMove(&myCMovePB,FALSE);
  1402.                         
  1403.                         PtoCstr(tempString);
  1404.                         
  1405.                         if (errCode != noErr)
  1406.                         {
  1407.                             sprintf(errorString,"ProcessDirectory:\rPBCatMove(%s) error %d",tempString,errCode);
  1408.                             ErrorAlert(errorString);
  1409.                             errCode = noErr;
  1410.                         }
  1411.                         
  1412.                         else
  1413.                             index--;
  1414.                     }
  1415.                 }
  1416.             }
  1417.         }
  1418.         
  1419.     } while (errCode==noErr);
  1420.     
  1421.     if (errCode == fnfErr)
  1422.         errCode = noErr;
  1423.     
  1424.     
  1425.     
  1426.     if (errCode == noErr)
  1427.     {
  1428.         index = 1;
  1429.             
  1430.         do
  1431.         {
  1432.             tempString[0] = 0;
  1433.             
  1434.             myCPB.hFileInfo.ioCompletion = 0L;
  1435.             myCPB.hFileInfo.ioNamePtr = (StringPtr) &tempString;
  1436.             myCPB.hFileInfo.ioVRefNum = vRefNum;
  1437.             myCPB.hFileInfo.ioFDirIndex = index++;
  1438.             myCPB.hFileInfo.ioDirID = theIODirID;
  1439.             
  1440.             errCode = PBGetCatInfo(&myCPB,FALSE);
  1441.             
  1442.             if (errCode!=noErr && errCode!=fnfErr)
  1443.             {
  1444.                 sprintf(errorString,"ProcessDirectory:\rPBGetCatInfo error %d",errCode);
  1445.                 ErrorAlert(errorString);
  1446.                 return(errCode);
  1447.             }
  1448.             
  1449.             else if (errCode == noErr && myCPB.dirInfo.ioFlAttrib & 0x10 && myCPB.dirInfo.ioDrDirID != studentWorkDirID)
  1450.             {
  1451.                 PtoCstr(tempString);
  1452.                 strcpy(errorString,currentDirName);
  1453.                 strcat(currentDirName,":");
  1454.                 strcat(currentDirName,tempString);
  1455.                 strcpy(tempString,errorString);
  1456.                 
  1457.                 errCode = ProcessDirectory(myCPB.dirInfo.ioDrDirID);
  1458.                 
  1459.                 strcpy(currentDirName,tempString);
  1460.             }
  1461.             
  1462.         } while (errCode==noErr);
  1463.         
  1464.         if (errCode == fnfErr)
  1465.             errCode = noErr;
  1466.     }    
  1467.     
  1468.     FlushVol("\p",vRefNum);
  1469.     
  1470.     return(errCode);
  1471. }
  1472.